import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Line2D.Double;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.TreeMap;

/**
 * 
 * @author Adam and Terry
 * 
 */
public class Road {

	private static final long serialVersionUID = 741713763308816772L;
	private String name;
	private Color colour;
	private int thickness;
	private boolean solid;
	private boolean changed;
	private Path2D.Double drawPath;
	private TreeMap<String, Road> intersections;

	private ArrayList<Line2D.Double> sections;
	private int type;
	private int lanes;
	private double weight;
	
	/**
	 * 
	 * @param name
	 * @param delimiter
	 */
	public Road(String name) {
		this.name = name;
		this.changed = false;
		this.solid = true;
		this.thickness = 0;
		this.drawPath = new Path2D.Double();
		this.intersections = new TreeMap<String, Road>();
		this.sections = new ArrayList<Line2D.Double>();
		weight = 0;
	}
	
	
	
	public int getType()
	{
		return this.type;
	}

	public Path2D.Double getDrawPath() {
		return this.drawPath;
	}

	/**
	 * 
	 * @return get the road name
	 */

	public String getName() {
		return name;
	}
	
	public void setName(String name)
	{
		this.name = name;
	}
	
	public void setChanged(boolean changed)
	{
		
		this.changed = changed;
	}
	
	public boolean getChanged()
	{
		return this.changed;
	}

	/**
	 * 
	 * @return
	 */
	public double getWeight() {
		return weight;
	}
	
	/**
	 * 
	 * @return get the road colour
	 */

	public Color getColour() {
		return this.colour;
	}

	/**
	 * 
	 * @return get the road thickness
	 */

	public int getThickness() {
		return this.thickness;
	}

	public void append(Point2D.Double p1, Point2D.Double p2) {
		drawPath.append(new Line2D.Double(p1, p2), true);
	}

	/**
	 * 
	 * @return get the road solid
	 */

	public boolean getSolid() {
		return this.solid;
	}
	
	public void setColour(Color colour)
	{
		this.colour = colour;
	}

	public void setType(int type) {
		switch (type) {
		case 0:
			this.colour = Color.green;
			this.thickness = 16;
			break;
		case 1:
			this.colour = Color.black;
			this.thickness = 12;
			break;
		case 2:
			this.colour = Color.red;
			this.thickness = 8;
			break;
		case 3:
			this.colour = Color.orange;
			this.thickness = 6;
			break;
		case 4:
		case 5:
			this.colour = new Color(150, 75, 0); // Brown RGB
			this.thickness = 4;
			break;
		default:

		}
		this.type = type;
	}
	
	public void setLanes(int num) {
		lanes = num;
	}
	
	public int getLanes()
	{
		return this.lanes;
	}

	public ArrayList<Line2D.Double> getSections() {
		return sections;
	}

	public void addSection(Line2D.Double sect) {
		sections.add(sect);
	}

	public void addIntersection(Road intsctn, Point2D.Double pt) {
		intersections.put(pt.toString(), intsctn);
	}

}
